import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../common/ObjCreate";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { HitEggProgressBar } from "./HitEggProgressBar";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { HitEggRewardRenderer } from "./HitEggRewardRenderer";
import { ScrollPolicy } from "../../../../flashx/textLayout/container/ScrollPolicy";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { SHitEggReward } from "../../../../Message/Game/SHitEggReward";
type int = number;
//class HitEggGiftPanel
    
    export  class HitEggGiftPanel extends GSprite
    {
        constructor()
        {
            super();
            this._nodeArr = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._giftBg = ObjCreate.createBitmap(null, 0, 0, this);
            this._title = ObjCreate.createBitmap(null, 35, 10, this);
            this._times = ObjCreate.createBitmap(null, 90, 395, this);
            LoaderHelp.addResCallBack(ResFileConst.BreakEgg, this.onResLoaded);
            this._hitEggProgressBar = new HitEggProgressBar(ImagesConst.breakEgg_Bottom);
            this._hitEggProgressBar.progressBarClass = ImagesConst.breakEgg_Bar;
            this._hitEggProgressBar.x = 10;
            this._hitEggProgressBar.y = 55;
            this._hitEggProgressBar.setProgressPosition(36, 0);
            this._hitEggProgressBar.startPointY = 76;
            this._hitEggProgressBar.setValue(0, 100);
            addChild(this._hitEggProgressBar);
            var loc1=Language.getString(36607);
            var loc2=ObjCreate.createGTextField(loc1, 0, 30, 245, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat5));
            this._tileList = ObjCreate.createTileList(80, 55, 160, 330, this);
            this._tileList.columnWidth = 155;
            this._tileList.rowHeight = 76;
            this._tileList.setStyle("cellRenderer", HitEggRewardRenderer);
            this._tileList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._tileList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._tileList);
            this._tileList.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onPaneMouseDownHandler);
            this._processTxt = ObjCreate.createGTextField("", 155, 393, 80, 20, this, GlobalStyle.textFormatGreen);
            var loc3=ObjCreate.createGButton(Language.getString(36608), 90, 417, 80, 25, this);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshBtnClickHandler);
            return;
        }

        /* internal  */onPaneMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onRefreshBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.HitEggOpenReq));
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._giftBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.breakEggGiftBg);
            this._title.bitmapData = GlobalClass.getBitmapData(ImagesConst.breakEggGiftTitle);
            this._times.bitmapData = GlobalClass.getBitmapData(ImagesConst.breakEggTimes);
            return;
        }

        public updateProgress(arg1: int): void
        {
            this._process = arg1;
            this._processTxt.text = arg1 + "";
            if (this._lastNode && this._lastNode.node >= arg1) 
            {
                this._hitEggProgressBar.setValue(arg1, this._lastNode.node);
            }
            var loc1=0;
            var loc2=this._nodeArr.length;
            var loc3=0;
            loc3 = 0;
            while (loc3 < loc2) 
            {
                if (arg1 >= this._nodeArr[loc3] && arg1 < this._nodeArr[(loc3 - 1)] && loc3 > 0 || loc3 == 0 && arg1 > this._nodeArr[0]) 
                {
                    loc1 = loc3;
                    break;
                }
                else if (loc3 == (loc2 - 1) && arg1 < this._nodeArr[(loc2 - 1)]) 
                {
                    loc1 = -1;
                    break;
                }
                ++loc3;
            }
            this._tileList.selectedIndex = loc1;
            return;
        }

        public updateHitEggActiveInfo(arg1: Array<any>): void
        {
            var loc1=null;
            this._nodeArr.splice(0);
            var loc2=arg1.length;
            var loc3=[];
            var loc4=0;
            while (loc4 < loc2) 
            {
                loc1 = arg1[loc4];
                if (loc1) 
                {
                    this._nodeArr.push(loc1.node);
                    loc3.push(loc1);
                }
                ++loc4;
            }
            this._nodeArr.sort(Array.NUMERIC | Array.DESCENDING);
            this._tileList.dataProvider = new DataProvider(loc3.sortOn("node", Array.NUMERIC | Array.DESCENDING));
            if (loc2 > 0) 
            {
                this._lastNode = loc3[0];
            }
            return;
        }

        /* internal */ /* var */_hitEggProgressBar: HitEggProgressBar;

        /* internal */ /* var */_giftBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_title: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_times: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_processTxt: GTextFiled;

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_lastNode: SHitEggReward;

        /* internal */ /* var */_process: int;

        /* internal */ /* var */_nodeArr: Array<any>;
    }
